package com.kpx.app.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;

import com.kpx.app.R;
import com.kpx.app.base.ActivityBase;
import com.kpx.app.http.HttpDataApi;
import com.kpx.app.http.HttpDataLoader;
import com.kpx.app.http.HttpDataReqUrl;
import com.kpx.app.http.ResObj;
import com.kpx.app.utils.EmojiUtil;
import com.kpx.app.utils.MyHashMap;
import com.kpx.app.utils.UIUtils;
import com.kpx.app.utils.uiutils.ToastUtil;
import com.kpx.app.view.TitleView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/4/3.
 * 意见反馈
 */

public class ActivityMySuggestions extends ActivityBase {
    @BindView(R.id.titleview)
    TitleView titleview;
    @BindView(R.id.et_content)
    EditText etContent;

    @Override
    public void initview(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_suggestions);
        ButterKnife.bind(this);
        UIUtils.setNormalTitle(titleview, "反馈");
        titleview.setRight("提交", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toUp();
            }
        },R.color.white);
//        etContent.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                String str = EmojiUtil.INSTANCE.filterEmoji(etContent.getText().toString()); // 过滤特殊字符
//                if (!s.equals(str)) {
//                    etContent.setText(str);
//                    ToastUtil.getInstance().showToast(ActivityMySuggestions.this,"不支持emoji表情");
//                }
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//
//            }
//        });
    }

    private void toUp() {
        if (TextUtils.isEmpty(etContent.getText().toString().trim())) {
            ToastUtil.getInstance().showToast(ActivityMySuggestions.this, "请输入您的反馈建议");
            return;
        }
        showLoadingDialog();
        MyHashMap map = new MyHashMap();
        map.put("content",etContent.getText().toString().trim());
        new HttpDataLoader(new HttpDataApi.OnRequestCallback() {
            @Override
            public void onRequestSuccess(String url, ResObj result, boolean isFrmCache) {
                dissmissLoadingDialog();
                if (result.getCode() == 0) {
                    ToastUtil.getInstance().showToast(ActivityMySuggestions.this, "提交成功，感谢您的反馈！");
                    finish();
                } else {
                    ToastUtil.getInstance().showToast(ActivityMySuggestions.this, result.getMsg());
                }
            }

            @Override
            public void onRequestError(String url, int statusCode, String error) {
                dissmissLoadingDialog();
                ToastUtil.getInstance().showToast(ActivityMySuggestions.this, error);
            }

        }, null, null).POST(HttpDataReqUrl.URL_GET_SUGGESTIONS_BACK, true, map);
    }

    @Override
    public void initData() {

    }

    @Override
    public void onReceiver(Context context, Intent intent) {

    }
}
